package com.tlgen.controller.system;

import com.tlgen.model.Dean;
import com.tlgen.model.RespBean;
import com.tlgen.service.DeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: tlgen
 * @Discription:
 */
@RestController
@RequestMapping("/system/dean")
public class DeanController {

    @Autowired
    DeanService deanService;

    @GetMapping("/")
    public List<Dean> getAllInstitutes() {
        return deanService.getAllDeans();
    }

    @PostMapping("/")
    public RespBean addInstitute(@RequestBody Dean dean) {
        if (deanService.addDean(dean) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @PutMapping("/")
    public RespBean updateDean(@RequestBody Dean dean) {
        if (deanService.updateDean(dean) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteDeanById(@PathVariable Integer id) {
        if (deanService.deleteDeanById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @DeleteMapping("/")
    public RespBean deleteDeanByIds(Integer[] ids) {
        if (deanService.deleteDeanByIds(ids) == ids.length) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }
}
